/**
 * The contents of this file are subject to the license and copyright detailed in the LICENSE and NOTICE files at the root of the source tree and available online at
 * http://www.askosi.org/license.html
 */
package be.destin.skos.view;

import javax.xml.bind.annotation.XmlEnum;

import be.destin.skos.html.SkosHtmlManager;

/**
 * @author Christophe Dupriez
 *
 */
@XmlEnum(String.class)
public enum SkosViewType {
	FREQ, ALFA, TREE;

	public static String list() {
		StringBuffer result = new StringBuffer();
		SkosViewType[] types = SkosViewType.values();
		for (int i=0; i<types.length; i++) {
			SkosViewType aType = types[i];
			result.append(aType.toString());
			if ( (i+1) < types.length) result.append(", ");
		}
		return result.toString();
	}

	public static String toHtmlButtons(SkosHtmlManager skosHtmlManager, String script, SkosViewType current, int maxDepth, String parameter) {
		StringBuffer buttons = new StringBuffer();
		for (SkosViewType aViewType : SkosViewType.values()) {
			if (aViewType == current) {
				buttons.append("<img");
				buttons.append(skosHtmlManager.askosiIcon("view_sort_"+aViewType.name().toLowerCase()));
				buttons.append(" class=\"imagelinkbuttonpressed\"/>");				
			} else {
				if (maxDepth > 1 || aViewType != TREE) {
					buttons.append("<a href=\"javascript:");
					buttons.append(script);
					buttons.append("('");
					buttons.append(aViewType.name());
					buttons.append("','");
					buttons.append(parameter);
					buttons.append("')\"><img");
					buttons.append(skosHtmlManager.askosiIcon("view_sort_"+aViewType.name().toLowerCase()));
					buttons.append(" class=\"imagelinkbutton\"/></a>&nbsp;");
				}
			}
			buttons.append("&nbsp;");
		}
		return buttons.toString();
	}
}
